package SentenceTranslator;


import java.util.ArrayList;
import java.util.List;
import Include.TACLine;
import Include.ASMConstructor;
import Common.REG;
import Common.RelacedEeg;
import Main.SymbolManager;

public class FunparaTranslator {
    public List<String> SentenceTranslate(SymbolManager symbolManager, TACLine tacLine) {
        List<String> asmLines = new ArrayList<>();
        String parEncode = symbolManager.encodeVar(tacLine.src1.value);
        int paraMem = symbolManager.para();
        REG dstReg = symbolManager.getReg(parEncode, "");
        if (dstReg == REG.Cnts) {
            RelacedEeg replacedReg = symbolManager.getReplacedReg();
            dstReg = replacedReg.reg;
            symbolManager.pushReg(dstReg,1);
            asmLines.add(ASMConstructor.construct_asm("push", dstReg));
        }
        asmLines.add(ASMConstructor.construct_asm("mov", dstReg, String.valueOf(paraMem)));
        symbolManager.setAvalueReg(parEncode, dstReg);
        if (symbolManager.avalueMem(parEncode) != -1) {
            int dstMem = symbolManager.avalueMem(parEncode);
            asmLines.add(ASMConstructor.construct_asm("mov", String.valueOf(dstMem), dstReg));
        }
        return asmLines;
    }
}

